let sscId = $(".select_item").attr("value");
let abnormalunFinishTable;
let InactiveLessonsTable;
let teacherRankTable;
let trackRemindTable;
let stuOrderInfoTable;
let materialFinishedTable;
let ocNewStudentTable;
let oldStuFollowTable;
let stuEvaluationTable;
let renewOrdersTable;
let leaveTeacherStuTable;
let newStuYfzTable;

//初始化页面框架
$(function () {
    let configList = selectSort(sscConfig);
    for (var i = 0; i < configList.length; i++) {
        if (configList[i].state != 0) {
            // console.log("sscConfig configList[i].method=>", configList[i].method)
            eval(configList[i].method);
        }
    }

    // 点击关闭按钮
    $(".close_icon").click(function () {
        $(this).parents('.main-box').remove()
    });
});

//点击排序设置，获取 排序列表
function sortConfig() {
    let configList = selectSort(sscConfig);
    //排序列表公共方法
    pubSortList(configList);
}

//还原默认设置 方法
function restoreDefaultConfig() {
    //调用公共方法
    restoreDefault(sscConfig);
}

//提醒列表 1
function trackRemindBysscId(id, tableName) {
    var html = '<span class="date_box">';
    html += '   <a href="javascript:" style="color: #fff" id="trackRemindDate">2019-01-07</a>';
    html += '<i class="fa fa-calendar" style="margin-left: 5px"></i>';
    html += '</span>';
    pubHtml(id, 3, tableName, html, "");
}

//订单到期外框 2
function stuOrderInfoBySsc(id, tableName) {
    pubHtml(id, 1, tableName, "", "");
}

//教材快学完列表 3
function materialFinished(id, tableName) {
    pubHtml(id, 2, tableName, "", "");
}

//新学员跟踪 4
function ocNewStudent(id, tableName) {
    pubHtml(id, 4, tableName, "", "");
}

//老学员跟进 5
function oldStuFollow(id, tableName) {
    pubHtml(id, 3, tableName, "", "");
}

//未正常完成课程学员 6
function abnormalunFinishLessons(id, tableName) {
    pubHtml(id, 1, tableName, "", "");
}

//Inactive学员 7
function inactiveLessons(id, tableName) {
    pubHtml(id, 4, tableName, "", "");
}

//老师投诉学员  8
function teacherRank(id, tableName) {
    pubHtml(id, 2, tableName, "", "");
}

//学员投诉 9
function stuEvaluation(id, tableName) {
    pubHtml(id, 3, tableName, "", "");
}

//订单续费 10
function renewOrders(id, tableName) {
    pubHtml(id, 4, tableName, "", "");
}

//离职老师常用学员 11
function leaveTeacherStu(id, tableName) {
    pubHtml(id, 1, tableName, "", "");
}

//新生预防针调查问卷 12
function newStuYfz(id, tableName) {
    pubHtml(id, 2, tableName, "", "");
}

//ssc 提醒数据表渲染 1-1
layui.use(['table', 'laydate'], function () {
    var table = layui.table;
    var laydate = layui.laydate;
    trackRemindTable = table;
    table.render({
        elem: '#1',
        url: '/SSCNewMain/selectTrackRemindBySsc',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',3,' + row.remindId + ')">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {
                    field: 'releaseTime', title: '提醒时间',
                    templet: function (row) {
                        if (row.expired == 1) {
                            return '<span style="color: #bd2130;">' + FormatTime(row.releaseTime) + '</span>';
                        } else {
                            return '<span style="color: #1abd76;">' + FormatTime(row.releaseTime) + '</span>';
                        }
                    }
                },
                {field: 'remark', title: '客户属性'}
            ]
        ],
        id: "selectTrackRemind"
    });
    //日期插件  重新加载
    laydate.render({
        elem: "#trackRemindDate",//制定元素
        value: new Date(),
        done: function (value, date) {//value, date, endDate点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
            //执行重载
            table.reload("selectTrackRemind", {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    "searchDate": value
                }
            });
        }
    });
});

//ssc 订单到期列表渲染 2-2
layui.use('table', function () {
    var table = layui.table;
    stuOrderInfoTable = table;
    table.render({
        elem: '#2',
        url: '/SSCNewMain/searchStuOrderInfoBySSC',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',4)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'packageName', title: '订单名称'},
                {
                    field: 'surplusValid', title: '到期日期',
                    templet: function (row) {
                        return FormatTime(row.surplusValid, 0);
                    }
                },
                {field: 'remainingCourses', title: '剩余币/课时数'}
            ]
        ],
        id: "searchStuOrderInfo"
    });
});

//ssc 教材将学完列表渲染 3-3
layui.use('table', function () {
    var table = layui.table;
    materialFinishedTable = table;
    table.render({
        elem: '#3',
        url: '/SSCNewMain/selectMaterialFinishedBySSC',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',5)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'packageName', title: '订单名称'},
                {field: 'enName', title: '教材'},
                {field: 'currentPage', title: '当前页码'},
                {field: 'maxPage', title: '最大页码'}
            ]
        ],
        id: "selectMaterialFinished"
    });
});

//ssc 新学员跟踪列表渲染 4-4
layui.use('table', function () {
    var table = layui.table;
    ocNewStudentTable = table;
    table.render({
        elem: '#4',
        url: '/SSCNewMain/selectOcNewStudent',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',6)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'remark', title: '订单开始天数'},
                {field: 'testMark', title: '回访次数'}
            ]
        ],
        id: "ocNewStudent"
    });
});

//ssc 老学员跟进 列表渲染 5-5
layui.use('table', function () {
    var table = layui.table;
    oldStuFollowTable = table;
    table.render({
        elem: '#5',
        url: '/SSCNewMain/oldStuFollow',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',7)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'phone', title: '手机'},
                {field: 'testMark', title: '未回访天数'}
            ]
        ],
        id: "oldStuFollow"
    });
});


//ssc 未正常完成课程学员 列表渲染 6-6
layui.use('table', function () {
    var table = layui.table;
    abnormalunFinishTable = table;
    table.render({
        elem: '#6',
        url: '/SSCNewMain/abnormalunFinishLessons',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',1)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'phone', title: '手机'},
                {field: 'remark', title: '次数'},
                {
                    field: '', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="publishStuDynamic(' + row.id + ',1)"" href="javascript:void(0);"> 完 成 </a>';
                    }
                },
            ]
        ],
        id: "abnormalunFinishLessons"
    });
});

//ssc inactive学员 列表渲染 7-7
layui.use('table', function () {
    var table = layui.table;
    InactiveLessonsTable = table
    table.render({
        elem: '#7',
        url: '/SSCNewMain/selectInactiveLessons',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',2)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'remark', title: '未约课天数'},
                {field: 'sscName', title: '学习顾问'},
                {
                    field: '', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="publishStuDynamic(' + row.id + ',2)" href="javascript:void(0);"> 完 成 </a>';
                    }
                },
            ]
        ],
        id: "InactiveLessons"
    });
});

//ssc 老师投诉学员 列表渲染 8-8
layui.use('table', function () {
    var table = layui.table;
    teacherRankTable = table;
    table.render({
        elem: '#8',
        url: '/SSCNewMain/selectTeacherRank',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',8)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'teacherName', title: '老师'},
                {
                    field: 'releaseTime', title: '上课时间',
                    templet: function (row) {
                        return '<span>' + FormatTime(row.releaseTime) + '</span>';
                    }
                },
                {
                    field: '', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="teacherReply(' + row.lessonId + ',8)" href="javascript:void(0);"> Edit </a>';
                    }
                },
            ]
        ],
        id: "teacherRankId"
    });
});

//ssc 学员投诉 列表渲染 9-9
layui.use('table', function () {
    var table = layui.table;
    stuEvaluationTable = table
    table.render({
        elem: '#9',
        url: '/SSCNewMain/selectstuEvaluationList',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',9)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'teacherName', title: '老师'},
                {
                    field: 'releaseTime', title: '上课时间',
                    templet: function (row) {
                        return '<span>' + FormatTime(row.releaseTime) + '</span>';
                    }
                },
                {
                    field: '', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="stuEvaluationInfo(' + row.lessonId + ')" href="javascript:void(0);"> 跟 进 </a>';
                    }
                },
            ]
        ],
        id: "stuEvaluation"
    });
});


//ssc 续费将启动学员 10
layui.use('table', function () {
    var table = layui.table;
    renewOrdersTable = table
    table.render({
        elem: '#10',
        url: '/SSCNewMain/renewOrders',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',23)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'enName', title: '套餐'},
                {field: 'testMark', title: '距离生效日期天数'},
                {
                    field: 'remark', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="updateRenewOrdersfinish(\'' + row.remark + '\')" href="javascript:void(0);"> 完 成 </a>';
                    }
                },
            ]
        ],
        id: "renewOrders"
    });
});

function renewOrdersReload() {
    renewOrdersTable.reload("renewOrders", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

// ssc 离职老师常用学员 11
layui.use('table', function () {
    var table = layui.table;
    leaveTeacherStuTable = table
    table.render({
        elem: "#11",
        url: '/SSCNewMain/leaveTeacherStu',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.personId + ',\'' + row.cnName + '\',23)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'phone', title: '手机'},
                {field: 'teacherName', title: '已离职常用老师'},
                {
                    field: 'remark', title: '操作',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="personInfo(' + row.personId + ',\'' + row.cnName + '\',23,0,9)"" href="javascript:void(0);"> 修改常用老师 </a>';
                    }
                },
            ]
        ],
        id: "leaveTeacherStu"
    })
});

// 刷新离职常用老师下面的学生列表
function reloadLeaveTeacherStu() {
    leaveTeacherStuTable.reload("leaveTeacherStu", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

// ssc 新生预防针调查问卷 12
layui.use('table', function () {
    var table = layui.table;
    newStuYfzTable = table
    table.render({
        elem: "#12",
        url: '/SSCNewMain/ocInfo',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": sscId},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学生登录名', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.personId + ',\'' + row.cnName + '\',23)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'phone', title: '手机'},
                {
                    field: 'releaseTime', title: '上课时间',
                    templet: function (row) {
                        return FormatTime(row.releaseTime);
                    }
                },
                {
                    field: 'remark', title: '回访问卷',
                    templet: function (row) {
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs" ' +
                            'onclick="doQuestionaire(' +
                            row.lessonId +
                            ',' + row.personId +
                            ',\'' + row.enName + '\'' +
                            ',\'' + row.cnName + '\'' +
                            ',\'' + row.teacherName + '\'' +
                            ',\'' + FormatTime(row.releaseTime) + '\'' +
                            ',\'' + row.sscName + '\'' +
                            ',\'' + row.stuLoginName + '\'' +
                            ')"' +
                            ' href="javascript:void(0);"> ' + "未回访" + ' </a>';
                    }
                }
            ]
        ],
        id: "newStuYfz"
    });
});

// 完成调查问卷
function doQuestionaire(lessonId, personId, enName, cnName, teacher, releaseTime, sscName, studentLogin) {
    var url = "/questionnaireOc/questionnairePaper?paperType=1" +
        "&lessonId=" + lessonId +
        "&personId=" + personId +
        "&enName=" + enName +
        "&cnName=" + cnName +
        "&teacher=" + teacher +
        "&releaseTime=" + releaseTime +
        "&sscName=" + sscName +
        "&studentLogin=" + studentLogin;
    console.log("yfz url=>", url);
    layer.open({
        id: 'insert-form',
        type: 2,
        title: "",
        closeBtn: 1, //显示关闭按钮
        shade: [0.5],
        area: ['98%', '99%'],
        // offset: 'rb', //右下角弹出
        // time: 2000, //2秒后自动关闭
        // maxmin: true, //开启最大化最小化按钮
        anim: 2,
        content: [url, 'no'], //iframe的url，no代表不显示滚动条
        end: function (index, layer) { //此处用于演示
            reloadNewStuYfz();
        }
    });
}

// 刷新新生预防针调查问卷下面的学生列表
function reloadNewStuYfz() {
    newStuYfzTable.reload("newStuYfz", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

function updateRenewOrdersfinish(orderId) {
    layer.confirm('是否确认完成?', {
        btn: ['是', '否'] //按钮
        , cancel: function (index, layero) {
            //取消操作，点击右上角的X
        }
    }, function () {
        $.ajax({
            type: 'post',
            url: '/SSCNewMain/updateRenewOrdersfinish ',
            data: {'orderId': orderId},
            cache: false,
            async: false,
            dataType: 'json',
            success: function (data) {
                if (data.code > 0) {
                    layer.msg("完成成功", {icon: 1});
                    setTimeout(function () {
                        renewOrdersReload();
                    }, 2000);
                } else {
                    layer.msg("完成失败", {icon: 2});
                }
            }
        });
    }, function () {
        //否
    });
}

//未正常完成课程学员面板  点击完成并发布动态后，重新加载该面板
function reloadAbnormalunFinishLessons() {
    abnormalunFinishTable.reload("abnormalunFinishLessons", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//inactive 面板  点击完成并发布动态后，重新加载该面板
function reloadInactiveLessons() {
    InactiveLessonsTable.reload("InactiveLessons", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//提醒数据表 reload
function trackRemindBySsc() {
    trackRemindTable.reload("selectTrackRemind", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//订单到期 reload
function stuOrderBySsc() {
    stuOrderInfoTable.reload("searchStuOrderInfo", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//教材将学完列表 reload
function selectMaterialFinishedBySSC() {
    materialFinishedTable.reload("selectMaterialFinished", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//新学员oc跟进  reload
function selectOcNewStudent() {
    ocNewStudentTable.reload("ocNewStudent", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//老学员跟进 reload
function oldStuFollowBySsc() {
    oldStuFollowTable.reload("oldStuFollow", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//老师投诉 reload
function teacherRankReload() {
    teacherRankTable.reload("teacherRankId", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

// 学员投诉老师 reload
function stuEvaluationReload() {
    stuEvaluationTable.reload("stuEvaluation", {
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}

//老师投诉回复 弹窗
function teacherReply(lessonId) {
    //打开排序规则 列表弹窗
    var html = '<div class="layui-form-item layui-form-text">';
    html += '<div class="layui-input-block" style="margin-left: 16px;margin-top: 5px;">';
    html += '      <textarea placeholder="请输入内容" class="layui-textarea" id="reply" style="width: 330px;height: 130px;"></textarea>';
    html += '    </div>';
    html += '</div>';
    html += '<div class="layui-form-item">';
    html += '<div class="layui-input-block">';
    html += '<button class="layui-btn" lay-submit="" lay-filter="demo1" onclick="submitReply(' + lessonId + ')">提交</button>';
    html += '<button type="reset" class="layui-btn layui-btn-primary" onclick="layer.closeAll()">取消</button>';
    html += '</div>';
    html += '</div>';
    layer.open({
        title: "输入处理结果",
        type: 1,
        area: ['360px', '250px'],
        shadeClose: false, //点击遮罩关闭
        scrollbar: false, // 父页面 滚动条 禁止
        content: html
    });
}

//提交老师投诉回复
function submitReply(lessonId) {
    var reply = $("#reply").val().trim();
    if (reply == '') {
        layer.msg("回复内容不能为空");
        return;
    }
    $.ajax({
        type: "POST", //提交方式
        url: "/SSCNewMain/addTeacherRankReply",//路径
        data: {
            "lessonId": lessonId,
            "reply": reply
        },//数据，这里使用的是Json格式进行传输JSON.stringify(data),
        dataType: "json",
        success: function (data) {
            if (data.code > 0) {
                layer.msg("回复提交成功", {
                    offset: ['50%'],
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    teacherRankTable.reload("teacherRankId", {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                    layer.closeAll();
                });
            } else {
                layer.msg("提交失败");
            }
        },
        error: function (err) {
            console.log(err);
        }
    })
}

//学员评论（评论，标签，星星） 相关信息
function stuEvaluationInfo(lessonId) {
    $.ajax({
        type: "POST", //提交方式
        url: "/SSCNewMain/selectLessonInfoById",//路径
        data: {
            "lessonId": lessonId,
        },//数据，这里使用的是Json格式进行传输JSON.stringify(data),
        dataType: "json",
        success: function (data) {
            if (data.code > 0) {
                var lessons = data.lessons;
                var html = '<div class="layui-col-md12">';
                html += '<div class="layui-card">';
                html += '        <div class="layui-card-body">获得的星星：';
                html += '             <div id="start"></div>'
                html += '         </div>';
                html += '        <div class="layui-card-body">评论类容：';
                html += '             <span>' + lessons.evaluation + '</span>';
                html += '         </div>';
                html += '        <div class="layui-card-body">Tags & Comment：';
                html += '             <span>' + lessons.tagsCnName + '</span>';
                html += '         </div>';
                html += '</div>';
                html += '</div>';
                html += '<div class="layui-form-item">';
                html += '<div class="layui-input-block">';
                html += '<button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="demo1" onclick="nextStep(' + lessonId + ')">下一步</button>';
                html += '<button type="reset" class="layui-btn layui-btn-primary layui-btn-sm" onclick="layer.closeAll()">取消</button>';
                html += '</div>';
                html += '</div>';
                //打开弹窗
                layer.open({
                    title: "投诉信息",
                    type: 1,
                    area: ['330px', '300px'],
                    shadeClose: false, //点击遮罩关闭
                    scrollbar: false, // 父页面 滚动条 禁止
                    content: html
                });
                //星星初始化
                layui.use(['rate'], function () {
                    var rate = layui.rate;
                    //显示文字
                    rate.render({
                        elem: '#start'
                        , value: lessons.level //初始值
                    });
                });
            }
        },
        error: function (err) {
            console.log(err);
        }
    })
}


//下一步 课程异常原因
function nextStep(lessonId) {
    //关闭上个弹窗
    layer.closeAll();
    $.ajax({
        type: "POST", //提交方式
        url: "/SSCNewMain/showVoidReasonList",//路径
        data: {
            "lessonId": lessonId,
        },//数据，这里使用的是Json格式进行传输JSON.stringify(data),
        dataType: "json",
        success: function (data) {
            if (data.code > 0) {
                console.info(data.data);
                var reasonList = data.data.reasonList;
                var result = data.data.results;
                var html = '<form class="layui-form" action="">';
                for (var i = 0; i < reasonList.length; i++) {
                    html += '<div class="layui-form-item" pane="" style="margin-left: -85px;margin-bottom: 0px;">';
                    html += '    <div class="layui-input-block">';
                    if (reasonList[i].state > 0) {
                        html += '<input lay-filter="state" name="reasonId" type="checkbox" value="' + reasonList[i].id + '" lay-skin="primary" title="' + reasonList[i].cnName + '" checked>';
                        html += '<textarea name="reasonStr" placeholder="请输入内容" class="layui-textarea">' + reasonList[i].remark + '</textarea>';
                    } else {
                        html += '<input lay-filter="state" name="reasonId" type="checkbox" value="' + reasonList[i].id + '" lay-skin="primary" title="' + reasonList[i].cnName + '">';
                    }
                    html += '    </div>';
                    html += '  </div>';
                }
                html += ' <div class="layui-form-item">';
                html += '    <div class="layui-input-block">';
                if (result != null && result.type == 1) {
                    html += '<input type="radio" name="vstype" value="0" title="非投诉">';
                    html += '<input type="radio" name="vstype" value="1" title="投诉" checked>';
                } else {
                    html += '<input type="radio" name="vstype" value="0" title="非投诉" checked>';
                    html += '<input type="radio" name="vstype" value="1" title="投诉" >';
                }

                html += '    </div> ';
                html += '</div>';
                html += '</form>';
                html += '<div class="layui-form-item">';
                html += '<div class="layui-input-block">';
                html += '<button class="layui-btn layui-btn-normal layui-btn-sm" id="saveViod" lay-submit="" lay-filter="demo1" onclick="subVoidReason(' + lessonId + ',0)">保 存</button>';
                html += '<button class="layui-btn layui-btn-sm layui-btn-warm" id="saveViod2" lay-submit="" lay-filter="demo1" onclick="subVoidReason(' + lessonId + ',1)">结 案</button>';
                html += '<button type="reset" class="layui-btn layui-btn-primary layui-btn-sm" onclick="layer.closeAll()">取 消</button>';
                html += '</div>';
                html += '</div>';

                //打开弹窗
                layer.open({
                    title: "异常课程登记处理",
                    type: 1,
                    area: ['360px', '85%'],
                    shadeClose: false, //点击遮罩关闭
                    scrollbar: false, // 父页面 滚动条 禁止
                    content: html
                });

                //初始化  form 表单元素
                layui.use(['form', 'layedit', 'laydate'], function () {
                    var form = layui.form;
                    form.on('checkbox(state)', function (data) {
                        // console.log(data.elem); //得到checkbox原始DOM对象
                        // console.log(data.elem.checked); //是否被选中，true或者false
                        // console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                        // console.log(data.othis); //得到美化后的DOM对象
                        if (data.elem.checked) {
                            var html = '<textarea name="reasonStr" placeholder="请输入内容" class="layui-textarea"></textarea>';
                            data.othis.parent().append(html);
                        } else {
                            data.othis.parent().find("textarea").remove();
                        }
                    });
                    form.render();
                });

                if (result != null && result.state == 1) {
                    $("textarea[name='reasonStr']").attr("disabled", true);
                    $("input[name='reasonId']").attr("disabled", true);
                    $("#saveViod").hide();
                    $("#saveViod2").hide();
                    $("input[name='vstype']").attr("disabled", true);
                }
            }
        },
        error: function (err) {
            console.log(err);
        }
    })
}

//提交课程异常原因
function subVoidReason(lessonId, state) {
    var reasonList = $("input[name='reasonId']:checked");
    var reasonStr = $("textarea[name='reasonStr']");
    if (reasonList == null || reasonList.length == 0) {
        layer.msg("请选择异常原因");
        return;
    }

    var dataobj = {};
    dataobj.vstype = $("input[name='vstype']:checked").val();
    dataobj.state = state;
    dataobj.lessonId = lessonId;
    dataobj.reasonArray = [];
    for (var i = 0; i < reasonList.length; i++) {
        if ($(reasonStr[i]).val() == '') {
            layer.tips('请输入处理结果', $(reasonStr[i]), {
                tips: [1, '#0FA6D8'],
                tipsMore: false,
                time: 3000
            });
            return
        }
        var obj = {};
        obj.voidReasonId = $(reasonList[i]).val();
        obj.result = $(reasonStr[i]).val();
        dataobj.reasonArray.push(obj);
    }

    $.ajax({
        type: "POST", //提交方式
        url: "/SSCNewMain/addVoidReason",//路径
        data: JSON.stringify(dataobj),//数据，这里使用的是Json格式进行传输JSON.stringify(data),
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        success: function (data) {
            if (data.code == 1) {
                layer.msg('提交成功', {
                    offset: ['50%'],
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    layer.closeAll();
                    stuEvaluationTable.reload("stuEvaluation", {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                });
            } else {
                layer.msg("操作失败");
            }
        },
        error: function (err) {
            console.log(err);
            $("#sub").attr('disabled', false);
        }
    })

}






